package com.zzsy.shoppingpro.home.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.zzsy.shoppingpro.R;
import com.zzsy.shoppingpro.app.Config;
import com.zzsy.shoppingpro.home.bean.HomeBean;

import java.util.List;

/**
 * Created by Administrator on 2019/8/20 0020.
 */

public class HotGridViewAdapter extends BaseAdapter {

    private Context context;
    private List<HomeBean.ResultBean.HotInfoBean> data;;

    public HotGridViewAdapter(Context mContext, List<HomeBean.ResultBean.HotInfoBean> hot_info) {
        this.context = mContext;
        this.data = hot_info;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        HotViewHolder viewHolder;
        if(convertView == null){
            convertView = View.inflate(context, R.layout.item_hot_grid_view,null);
            viewHolder = new HotViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (HotViewHolder) convertView.getTag();
        }
        HomeBean.ResultBean.HotInfoBean hotInfoBean = data.get(position);
        Glide.with(context)
                .load(Config.BASE_URl_IMAGE + hotInfoBean.getFigure())
                .into(viewHolder.ivHot);
        viewHolder.tvName.setText(hotInfoBean.getName());
        viewHolder.tvPrice.setText("￥"+ hotInfoBean.getCover_price());
        return convertView;
    }

    private class HotViewHolder {
        ImageView ivHot;
        TextView tvName;
        TextView tvPrice;

        public HotViewHolder(View convertView) {
            ivHot = convertView.findViewById(R.id.iv_hot);
            tvName = convertView.findViewById(R.id.tv_name);
            tvPrice = convertView.findViewById(R.id.tv_price);
        }
    }
}